
import * as Cesium from "cesium";

class constellationEffect {
    viewer: Cesium.Viewer;
    constellationData: { name: string; stars: { id: number; position: number[]; name: string; }[]; lines: { start: number[]; end: number[]; }[]; }[];
    snowStage: Cesium.PostProcessStage
    constructor(viewer, options) {
        if (!viewer) throw new Error("no viewer object!");
        this.viewer = viewer
        // 加载星座数据
        this.constellationData = options
        this.init()
    }
    init() {
        this.constellationData.forEach((constellation) => {
            // 绘制星星
            constellation.stars.forEach((star) => {
                this.viewer.entities.add({
                    position: Cesium.Cartesian3.fromDegrees(star.position[0], star.position[1], star.position[2]),
                    point: { pixelSize: 10, color: Cesium.Color.YELLOW },
                    label: {
                        text: star.name,
                        font: "14pt sans-serif",
                        style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                        outlineWidth: 2,
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    },
                });
            })

            // 绘制星座线条
            constellation.lines.forEach((line) => {
                this.viewer.entities.add({
                    polyline: {
                        positions: Cesium.Cartesian3.fromDegreesArray([
                            ...line.start,
                            ...line.end,
                        ]),
                        width: 2,
                        material: Cesium.Color.BLUE,
                    },
                });
            });
        })
    }

    show(visible) {
        this.snowStage.enabled = visible;
    }

}

export default constellationEffect
